<template>
  <fullscreen ref="fullscreen" @change="fullscreenChange">
    <el-container  id="layout_app">
    <el-aside :width="flag?'63px':'200px'">
        <p style="white-space: nowrap;">小U商城后台</p>
        <el-menu
            :unique-opened="true"
            :collapse-transition="false"	
            :collapse="flag"
            default-active="2"
            class="el-menu-vertical-demo"
            @open="handleOpen"
            @close="handleClose"
            background-color="rgb(51, 51, 51)"
            text-color="#fff"
            router
            >
            <el-menu-item index="/home">
                <i class="el-icon-menu"></i>
                <span slot="title"> 管理中心</span>
            </el-menu-item>
            <el-submenu :index="menu.url" v-for="menu in menuList" :key="menu.id">
                <template slot="title">
                <i :class="menu.icon"></i>
                <span>{{ menu.title }}</span>
                </template>
                <el-menu-item-group>  
                  <el-menu-item v-for="m in menu.children" :key="m.id" :index="m.url">{{m.title}}</el-menu-item>
                </el-menu-item-group>
            </el-submenu>

            <!-- <el-submenu index="2">
                <template slot="title">
                <i class="el-icon-location"></i>
                <span> 系统设置</span>
                </template>
                <el-menu-item-group>  
                <el-menu-item index="/menu">菜单管理</el-menu-item>
                <el-menu-item index="/role">角色管理</el-menu-item>
                <el-menu-item index="/admin">管理员管理</el-menu-item>
                </el-menu-item-group>
            </el-submenu>

            <el-submenu index="3">
                <template slot="title">
                <i class="el-icon-location"></i>
                <span> 商城管理</span>
                </template>
                <el-menu-item-group>
                <el-menu-item index="/sort">商品分类</el-menu-item>
                <el-menu-item index="/specs">商品规格</el-menu-item>
                <el-menu-item index="/goods">商品管理</el-menu-item>
                <el-menu-item index="3-4">会员管理</el-menu-item>
                <el-menu-item index="3-5">轮播图管理</el-menu-item>
                <el-menu-item index="3-6">秒杀活动</el-menu-item>
                </el-menu-item-group>
            </el-submenu> -->
            
        </el-menu>
    </el-aside>
    <el-container>
        <el-header>
            <el-button @click="flag = !flag" type="primary" icon="el-icon-s-fold" size="mini"></el-button>
            <!-- 面包屑 -->
            <el-breadcrumb separator="/">
                <el-breadcrumb-item :to="{ path: '/' }">管理中心</el-breadcrumb-item>
                <el-breadcrumb-item><a href="/">菜单管理</a></el-breadcrumb-item>
            </el-breadcrumb>
            <!-- 按钮 -->
            <el-button icon="el-icon-back" circle size="mini"></el-button>
            <!-- 下拉菜单 -->
            <el-dropdown>
                <span class="el-dropdown-link">
                    admin<i class="el-icon-arrow-down el-icon--right"></i>
                </span>
                <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item>个人信息</el-dropdown-item>
                    <el-dropdown-item><span @click.stop="togglefullscreen">全屏预览</span></el-dropdown-item>
                    <el-dropdown-item><span @click.stop="logout">安全退出</span></el-dropdown-item>
                </el-dropdown-menu>
            </el-dropdown>
        </el-header>
        <el-main>
            <router-view></router-view>
        </el-main>
    </el-container>
    </el-container>
  </fullscreen>
</template>
<script>
import fullscreen from 'vue-fullscreen'
import Vue from 'vue'
import { mapMutations, mapState } from 'vuex'
Vue.use(fullscreen)

export default {
  data(){
    return {
      flag: false,
      fullscreen: false
    }
  },
  created(){
    this.menuListMutations()
 
 },
  computed:{
    ...mapState({menuList: state=> state.menuList})
  },
  methods: {
    ...mapMutations(['menuListMutations']),
    logout(){
      localStorage.clear();
      this.$router.push("/login")
    },
    togglefullscreen(){
      this.$refs.fullscreen.toggle()
    },
    fullscreenChange(fullscreen){
       this.fullscreen = fullscreen
    },
    handleOpen(){

    },
    handleClose(){

    }
  }
}
</script>

<style scoped>
  #layout_app{
      width: 100%;
      height: 100vh;
  }
  .el-header{
    background-color: #FFF;
    color: #333;
    line-height: 60px;
  }
  
  .el-aside {
    background-color: #D3DCE6;
    color: #333;
    text-align: center;
    /* 改过 */
    line-height: 60px;
    background-color: #444;
    color: white;
    font-weight: 400 !important;
    letter-spacing: 4px;
    font-size: 20px;
  }
  
  .el-main {
    background-color: #E9EEF3;
    color: #333;
  }
  
  body > .el-container {
    margin-bottom: 40px;
  }
  
  .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }
  
  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  }
  /* 修改侧面导航高度 */
  .el-menu{
      height: calc(100vh - 60px);
      /* width: 206px; */
  }
  /* 修改面包屑 */
  .el-breadcrumb{
      display: inline-block;
  }
  /* 下拉菜单 */
   .el-dropdown-link {
    cursor: pointer;
    color: #409EFF;
  }
  .el-dropdown {
    font-size: 12px;
    position: absolute;
    right: 20px;
  }
</style>